package com.houger.ddd.redpacket.controller;

import com.houger.ddd.common.utils.R;
import com.houger.ddd.redpacket.facade.dto.GrabRedPacketDto;
import com.houger.ddd.redpacket.facade.dto.RedPacketDto;
import com.houger.ddd.redpacket.controller.vo.GrabRedPacketResVo;
import com.houger.ddd.redpacket.integration.RedPacketService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/red-packet")
@Tag(name = "red-packet")
public class RedPacketController {

    @Autowired
    private RedPacketService redPacketService;

    @PostMapping("/send")
    @Operation(summary = "sendRedPacket", description = "发红包")
    public R<String> sendRedPacket(@RequestBody RedPacketDto redPacketDto) {
        return R.ok(redPacketService.sendRedPacket(redPacketDto));
    }

    @GetMapping("/grab/{redPacketId}/{userId}")
    public R<String> grabRedPacket(@PathVariable String redPacketId,@PathVariable String userId) {
        final GrabRedPacketDto dto = new GrabRedPacketDto();
        dto.setRedPacketId(redPacketId);
        dto.setUserId(userId);
        return R.ok(redPacketService.grabRedPacket(dto));
    }

    @GetMapping("/grab/list/{redPacketId}")
    public R<GrabRedPacketResVo> getGrabRedPacketList(@PathVariable String redPacketId) {
        return R.ok(redPacketService.getGrabRedPacketList(redPacketId));
    }
}
